*** Settings ***
Documentation    TC11-Lane Management FCL -Add and Delete New Lanes
Resource    ../../Keywords/Common_Head.robot
Force Tags    P3
Metadata    Author    Momo
Metadata    ID    6855103


*** Test Cases ***
TC11-Lane Management FCL -Add and Delete New Lanes
    Step 1 User Goes To Basic Data Management Tender List
    Step 2 User Goes To Pricing Collaboration Pricing Project
    Step 3 Input Following Attributes
    Step 4 User Selects Row That Project Name Is 20240815 FCL
    Step 5 Click On Copy Data
    Step 6 Input Tender ID With Value 2024000001 Click On Search
    Step 7 Select This Entry Click On Copy Data Button And Yes In
    Step 8 Select Current Project In Pricing Project Click On
    Step 9 Click Skip Button In Step4 and Yes In The Pop up
    Step 10 User Go Back To Pricing Project Page Select The Row
    Step 11 User Clicks Lane Management Button
    Step 12 User Selects Update Existing Lanes
    Step 13 User Clicks Next Button
    Step 14 User Clicks Back Button And Select Add New Lanes
    Step 15 User Clicks Next Button 2
    Step 16 User Clicks Upload Button In Step1
    Step 17 User Clicks Add File Button
    Step 18 User Select The FCLTemplate Location All xlsx index php
    Step 19 User User Select Location In Step2 And Mapping The
    Step 20 In Step4 User Checks Download After Generating
    Step 21 Download File Update The Container Type As 20DC In The
    Step 22 User Clicks Skip Button In Step 5
    Step 23 User Clicks Yes And Back Button
    Step 24 User Select Update Existing Lanes Clicks Next Button
    Step 25 User Clicks Download Button
    Step 26 User Open The Download Document
    Step 27 Click On Back Button Select Delete Existing Lanes
    Step 28 User Clicks Upload Button
    Step 29 User Clicks Download Template Link
    Step 30 User Modify The Download Document To Add Lane ID 3
    Step 31 User Clicks Confirm Button
    Step 32 Select Update Existing Lanes Clicks Next Button
    Step 33 User Clicks Download Button 2
    Step 34 Click On Close Button
    Step 35 Select This Project Click On Delete Project Button
    Step 35 User goes to Basic Data Management Tender List 2


*** Keywords ***
Step ${step} User Goes To Basic Data Management Tender List
    #************************Step 1******************************
    #  Do:
    #      User goes to Basic Data Management Tender List
    #      Click Create button
    #      Input with following attributes
    #      Tender ID some numbers such as 202408151435001 you can
    #     input with current datetime and some random number to
    #     avoid duplicate validation
    #      Tender Title some value such as Regression Test by
    #     Wendy001
    #      Customer 815 Miele
    #      Mode select all
    #      Level Global
    #      Click on Save button
    #  Expected:
    #      Created successfully with the message Tender has been
    #     added
    #************************************************************
    ${G_TENDERID}    Generate Tender ID
    ${TenderTitle}   Set Variable    Regression Test by auto
    Set Suite Variable     ${G_TENDERID}
    Login Space
    Create Tender    ${G_TENDERID}    ${TenderTitle}    815    true    true    true
    ${PROJECT}    Copy Dictionary    ${PROJECT_PARAM}
    Set To Dictionary    ${PROJECT}
    ...    TENDER_ID=${G_TENDERID}    TENDER_TITLE=${TenderTitle}    CUSTOEMR_NAME=Miele    CUSTOMER_LEVEL=Global
    ...   MODE=FCL    DEPUTY=SNOWLI01    TEMPLATE=${CURDIR}${/}TestData${/}FCLTemplate-Location-All.xlsx
    Set Suite Variable     ${PROJECT}
    ${Title}    Set Variable    ${PROJECT.TENDER_ID}-${PROJECT.MODE}-${PROJECT.TENDER_TITLE}
    Set Suite Variable    ${Title}    ${Title}

Step ${step} User Goes To Pricing Collaboration Pricing Project
    #************************Step 2******************************
    #  Do:
    #      User goes to Pricing Collaboration Pricing Project
    #      User clicks Create Project button
    #  Expected:
    #      A New Project dialog should be opened successfully
    #************************************************************
    Create Project    ${PROJECT}

Step ${step} Input Following Attributes
    #************************Step 3******************************
    #  Do:
    #      Input following attributes
    #      Tender ID 20240815 Regression
    #      Mode FCL
    #      Deadline to TM current date 10 day
    #      Rate Validity From current date
    #      Rate Validity To current date 100 day
    #      Deputies NATZHANG
    #      Description for regression
    #      Click on Save button
    #  Expected:
    #      A new project is created successfully
    #************************************************************
    Log    Done in step 3

Step ${step} User Selects Row That Project Name Is 20240815 FCL
    #************************Step 4******************************
    #  Do:
    #      User selects row that project name is 20240815 FCL
    #     Regression
    #  Expected:
    #      The row can be selected successfully
    #************************************************************
    Search Project    ${PROJECT.TENDER_ID}

Step ${step} Click On Copy Data
    #************************Step 5******************************
    #  Do:
    #      Click on Copy Data
    #  Expected:
    #      A dialogue named Copy Target to Project 20240815 FCL
    #     Regression display
    #      Search Criteria
    #      Mode with value FCL uneditable
    #      Customer name with no value
    #      Tender ID with value ALL Editable
    #      Tender Lead with value ALL Editable
    #      RFQ Launch Date with value DD MM YYYY Editable
    #      Search button
    #      Result list has no entry present
    #      Copy Data button is disable now
    #************************************************************
    Copy Data    2024000001    FCL    do not touch me

Step ${step} Input Tender ID With Value 2024000001 Click On Search
    #************************Step 6******************************
    #  Do:
    #      Input Tender ID with value 2024000001 click on Search
    #     button
    #  Expected:
    #      Result list has one entry as above information
    #************************************************************
    Log    Done in step 5

Step ${step} Select This Entry Click On Copy Data Button And Yes In
    #************************Step 7******************************
    #  Do:
    #      Select this entry click on Copy Data button and Yes in
    #     pop up window
    #  Expected:
    #      Successfully with messages in pop up window
    #      Tender has been successfully copied from 2024000001 FCL
    #     do not touch me
    #      Please adjust the template and the lanes in Template
    #     Lane Management page if required
    #      After click on OK button
    #      The same message is displayed in Pricing Project page
    #     too
    #************************************************************
    Log    Done in step 5

Step ${step} Select Current Project In Pricing Project Click On
    #************************Step 8******************************
    #  Do:
    #      Select current project in pricing project click on
    #     template management button
    #  Expected:
    #      In the dialog check the information under Step2 should
    #     be the same as project 2024000001 FCL do not touch me
    #************************************************************
    Search Project    ${PROJECT.TENDER_ID}
    Wait Until Search Finished
    Wait Until Keyword Succeeds    5x    300ms    Click    ${Project_toolbar_TemplateManagementButton}
    Sleep    2
    Get Checkbox State    //span[contains(text(),'Origin items')]/../..//input    ==    checked
    ${value}    get Text    ((//label[contains(.,'TBN')])[1]/../div/div//input)[9]
    Should Be Equal    ${value}    CURRENCY
    Click    ${Template_OriginLocalChargesTab}
    Get Checkbox State    //label[contains(.,'DB Schenker offer free time in days(Calendar Da ...')]//input    ==    checked
    ${value}    get Text    ((//label[contains(.,'TBN')])[2]/../div/div//input)[6]
    Should Be Equal    ${value}    2
    Click    ${Template_RelatedOriginChargesTab}
    Get Checkbox State    //label[contains(.,"Free in Charge (if applicable)")]/../../div//span[contains(text(),"40'/40HQ")]/../..//input[1]    ==    checked
    Click    ${Template_OceanTransportChargesTab}
    Get Checkbox State    //span[contains(text(),'Main Leg Origin / POL')]/../..//input    ==    checked
    ${value}    get Text    ((//label[contains(.,'TBN')])[3]/../div/div//input)[14]
    Should Be Empty    ${value}
    Click   ${Template_DemurrageDetentionTab}
    Get Checkbox State    //label[contains(.,"DB SCHENKER Destination Demurrage")]/../../div//span[contains(text(),"Free Time at Destination 40'/40HQ (Calendar Days)")]/../..//input[1]    ==    checked
    Click    ${Template_RelatedDestinationChargesTab}
    Get Checkbox State    //label[contains(.,"Terminal Security Charge Destination")]/../../div//label[contains(.,'Flat Fee')]/../..//input    ==    checked
    Click    ${Template_DestinationLocalChangesTab}
    Get Checkbox State    //label[contains(.,'Transit Time From CY/RP/ICD to City in Days')]/../..//input    ==    checked
    ${value}    get Text    ((//label[contains(.,'TBN')])[4]/../div/div//input)[18]
    Should Be Equal    ${value}    currency

Step ${step} Click Skip Button In Step4 and Yes In The Pop up
    #************************Step 9******************************
    #  Do:
    #      Click Skip button in Step4 and Yes in the pop up
    #     windown
    #  Expected:
    #      Next Round Management button is enable
    #************************************************************
    Click    ${Template_SkipSendToGPDButton}
    Check Text Value    ${SkipSendToGPDMessage}    Are you sure to skip push pricing?
    Click    ${SkipSendToGPD_Yes}
    Wait Until Search Finished
    Wait Until Keyword Succeeds   20x    500ms    Get Element States    ${Template_gotoNextButton}    contains    visible    enabled
    Click    ${Project_RoundMgmt_CloseButton}
    Wait Until Search Finished

Step ${step} User Go Back To Pricing Project Page Select The Row
    #************************Step 10******************************
    #  Do:
    #      User go back to Pricing Project page select the row
    #     that contains the project
    #  Expected:
    #      1 The row can be selected successfully
    #      2 The button of lane management is enabled
    #************************************************************
    Search Project    ${PROJECT.TENDER_ID}
    Wait For Elements State    ${Project_toolbar_LaneManagementButton}    enabled    20

Step ${step} User Clicks Lane Management Button
    #************************Step 11******************************
    #  Do:
    #      User clicks Lane Management button
    #  Expected:
    #      1 A dialogue displays
    #      2 There are three check boxes update existing lanes
    #     delete existing lanes and add new lanes
    #      3 There are two boxes next and close
    #************************************************************
    Check A Dialog displays After Clicking Lane_Magm button    ${Title}

Step ${step} User Selects Update Existing Lanes
    #************************Step 12******************************
    #  Do:
    #      User selects Update existing lanes
    #  Expected:
    #      The check box can be selected successfully
    #************************************************************
    ${Status}    Run Keyword And Return Status    Get Checkbox State    ${Project_LaneMgmt_UpdateRadio}    ==    checked
    IF    '${Status}' == 'False'
        Click    ${Project_LaneMgmt_UpdateRadio}
    END
    Get Checkbox State    ${Project_LaneMgmt_UpdateRadio}    ==    checked

Step ${step} User Clicks Next Button
    #************************Step 13******************************
    #  Do:
    #      User clicks Next button
    #  Expected:
    #      A new dialogue appears There are four buttons in it
    #     Download Upload Back and Close
    #************************************************************
    Click If Enabled    ${Project_LaneMgmt_NextButton}
    Wait For Elements State    ${Project_LaneMgmt_UpdateLane_DownloadButton}     visible    30   60
    Wait For Elements State    ${Project_LaneMgmt_UpdateLane_UploadButton}     visible    30   60
    Wait For Elements State    ${Project_LaneMgmt_UpdateLane_BackButton}     visible    30   60
    Wait For Elements State    ${Project_LaneMgmt_UpdateLane_CloseButton}     visible    30   60

Step ${step} User Clicks Back Button And Select Add New Lanes
    #************************Step 14******************************
    #  Do:
    #      User clicks Back button and select add new lanes
    #  Expected:
    #      It can be checked successfully
    #************************************************************
    Click    ${Project_LaneMgmt_UpdateLane_BackButton}
    Wait For Elements State    ${Project_LaneMgmt_AddRadio}    visible    60
    Click    ${Project_LaneMgmt_AddRadio}

Step ${step} User Clicks Next Button 2
    #************************Step 15******************************
    #  Do:
    #      User clicks next button
    #  Expected:
    #      A new dialogue appears
    #      1 There are five steps in it
    #      2 In step 1 there are upload button
    #      3 Step2 Mapping Columns the matched columns are
    #     displayed
    #      4 Step 3 Validation
    #      5 Step 4 Add into Internal Pricing Template
    #      6 Step5 Push Pricing
    #      Back and Close button
    #************************************************************
    Click If Enabled    ${Project_LaneMgmt_NextButton}
    Wait For Elements State    ${Data_toolbar_UploadButton}     visible    30   
    Get Page Source    contains     Element    ${DataCleaning_MappingColumns}
    Get Page Source    contains     Element    ${DataCleaning_Validation}
    Get Page Source    contains     Element    ${DataCleaning_AddintoIPT}
    Get Page Source    contains     Element    ${DataCleaning_SendtoGPD}

Step ${step} User Clicks Upload Button In Step1
    #************************Step 16******************************
    #  Do:
    #      User clicks upload button in Step1
    #  Expected:
    #      A dialogue named upload template display
    #************************************************************
    Data Upload Template    ${Title}    ${PROJECT.TEMPLATE}

Step ${step} User Clicks Add File Button
    #************************Step 17******************************
    #  Do:
    #      User clicks add file button
    #  Expected:
    #      A file select dialogue display
    #************************************************************
    Log    Finish in step16

Step ${step} User Select The FCLTemplate Location All xlsx index php
    #************************Step 18******************************
    #  Do:
    #      User select the FCLTemplate Location All xlsx index php
    #     attachments get 149c60d8 27dc 4fe3 9420 6c386056defb
    #  Expected:
    #      The file name and date time with current time is
    #     displayed
    #************************************************************
    Log    Finish in step16

Step ${step} User User Select Location In Step2 And Mapping The
    #************************Step 19******************************
    #  Do:
    #      User User Select Location in step2 and mapping the
    #     default columns
    #      Origin Country country from D
    #      Destination Country country to G
    #      Origin City city from C
    #      Destination City city to F
    #      Origin State state from E
    #      Destination State state to H
    #      Customer Lane ID Lane ID code B
    #      Origin Type Origin Type I
    #      Destination Type Des Type J
    #      Origin Postal Code Origin Postal Code K
    #      Destination Postal Code Destination Postal Code L
    #      Customer s Delivery Term Customer s Delivery Term M
    #      Customer Port of Load Customer Port of Load N
    #      Customer Port of Discharge Customer Port of Discharge O
    #      Volume Containers 20 Volume Containers 20 P
    #      Volume Containers 40 Volume Containers 40 Q
    #      Volume Containers 40HC Volume Containers 40HC R
    #      Volume Containers 45 Volume Containers 45 S
    #      Volume TEU Total Volume TEU Total T
    #      Commodity Description Commodity Description U
    #      Commodity Remarks Commodity Remarks W
    #      IMO Class IMO Class V
    #      IMO UN No IMO UN No W
    #      and then clicks start button in step 3
    #  Expected:
    #      There is a detailed description in summary
    #      Summary Successful
    #      Please move to next step to start Generate Internal
    #     Pricing Template
    #      Download Upload Set Pass buttons are displayed
    #************************************************************
    Wait Until Keyword Succeeds    5x    300ms    Click    ${Project_DataClean_RoutingLocation}
    Wait For Elements State    ${FCL/AIR_Select_OriginCountry}    enabled    60
    FCL Select Location Routing    Location
    Click    ${Data_toolbar_StartButton}
    Wait Until Search Finished
    Check Text Value    ${Template_Summary}    Successful
    Get Page Source    contains    Please move to next step to start Generate Internal Pricing Template.
    Wait For Elements State    ${Summary_Succ}    visible    30
    Wait For Elements State   ${Data_toolbar_DownloadButton}     enabled
    Get Element States    ${Data_toolbar_UploadAfterStartButton}    contains    enabled
    Get Element States    ${Data_toolbar_SetPassButton}    contains    enabled

Step ${step} In Step4 User Checks Download After Generating
    #************************Step 20******************************
    #  Do:
    #      In Step4 User checks download after generating
    #     successfully and clicks start button
    #  Expected:
    #      A progress bar displays and the summary says Successful
    #      The new lanes have been inserted into the Internal
    #     Pricing Template successfully
    #************************************************************
    Click    ${Data_toolbar_StartButton}
    Wait Until Search Finished
    Check Text Value    ${Template_Summary}    Successful
    Get Page Source    contains    The new lanes have been inserted into the Internal Pricing Template

Step ${step} Download File Update The Container Type As 20DC In The
    #************************Step 21******************************
    #  Do:
    #      Download file Update the container type as 20DC in the
    #     downloaded file such as index php attachments get
    #     9e9b95b1 36d6 41ef 8ee3 5cf1b293a804
    #      index php attachments get 0207b147 34f4 4e35 9b73
    #     f88ef62f64bf Upload it
    #  Expected:
    #      Skip button in Step5 occurs
    #************************************************************
    ${Step4File}    Download File    css=[data-ng-click="downloadGeneratedTemplate()"]
    Open Excel Document    ${Step4File}    ${PROJECT.MODE}_D
    Write Excel Cell    7    173    20DC    ${PROJECT.MODE}_D
    Write Excel Cell    8    173    20DC    ${PROJECT.MODE}_D
    Write Excel Cell    7    46    ${EMPTY}    ${PROJECT.MODE}_D
    Write Excel Cell    7    47    ${EMPTY}    ${PROJECT.MODE}_D
    Write Excel Cell    8    46    ${EMPTY}    ${PROJECT.MODE}_D
    Write Excel Cell    8    47    ${EMPTY}    ${PROJECT.MODE}_D
    Save Excel Document   ${Step4File}
    Close All Excel Documents
    Reopen And Save Excel    ${Step4File}
    Click    ${Template_UploadButton}
    Wait For Elements State   ${upload_addFileButton}     enabled
    Upload File By Selector    ${upload_addFileButton}    ${Step4File}
    Click    //button[span[.="OK"]]

Step ${step} User Clicks Skip Button In Step 5
    #************************Step 21******************************
    #  Do:
    #      User clicks skip button in step 5
    #  Expected:
    #      A new dialogue displays and asks are you sure to skip
    #     push pricing
    #************************************************************
    Push Skip and check for AIR Template

Step ${step} User Clicks Yes And Back Button
    #************************Step 22******************************
    #  Do:
    #      User clicks yes and Back button
    #  Expected:
    #      The two dialogues disappears and only the three types
    #     lane management dialogue exists
    #************************************************************
    Click    ${Project_LaneMgmt_AddLane_BackButton}
    Wait Until Search Finished
    Wait For Elements State    ${Project_LaneMgmt_UpdateInfo}    visible    30
    Wait For Elements State    ${Project_LaneMgmt_DeleteInfo}    visible
    Wait For Elements State    ${Project_LaneMgmt_AddInfo}    visible
    Wait For Elements State    ${Project_LaneMgmt_NextButton}    visible
    Wait For Elements State    ${Project_LaneMgmt_CloseButton}    visible

Step ${step} User Select Update Existing Lanes Clicks Next Button
    #************************Step 23******************************
    #  Do:
    #      User Select update existing lanes clicks next button
    #  Expected:
    #      A new dialogue displays
    #************************************************************
    Click    ${Project_LaneMgmt_UpdateInfo}
    Click    ${Project_LaneMgmt_NextButton} 
    Wait Until Search Finished

Step ${step} User Clicks Download Button
    #************************Step 24******************************
    #  Do:
    #      User clicks download button
    #  Expected:
    #      The file can download successfully
    #************************************************************
    ${filename}    Download File    ${Project_UpdateLane_DownloadButton} 
    Set Suite Variable    ${filename}    ${filename}

Step ${step} User Open The Download Document
    #************************Step 25******************************
    #  Do:
    #      User open the download document
    #  Expected:
    #      In the document the added lane is in it there are 4
    #     lanes in Excel file
    #************************************************************
    Wait Until Search Finished
    Open Excel Document     ${filename}    ${PROJECT.MODE}_D
    Check Cell Value    5    17    1    ${PROJECT.MODE}_D
    Check Cell Value    6    17    2    ${PROJECT.MODE}_D
    Check Cell Value    7    17    3    ${PROJECT.MODE}_D
    Check Cell Value    8    17    4    ${PROJECT.MODE}_D
    Close All Excel Documents

Step ${step} Click On Back Button Select Delete Existing Lanes
    #************************Step 26******************************
    #  Do:
    #      Click on Back button select Delete Existing Lanes
    #  Expected:
    #      A new dialogue appears There are three buttons in it
    #     Upload Back and Close
    #************************************************************
    Click    ${Project_LaneMgmt_AddLane_BackButton}
    Click    ${Project_LaneMgmt_DeleteInfo}
    Click    ${Project_LaneMgmt_NextButton} 
    Wait Until Search Finished

Step ${step} User Clicks Upload Button
    #************************Step 27******************************
    #  Do:
    #      User clicks upload button
    #  Expected:
    #      A new dialogue named upload template displays
    #************************************************************
    Click    ${Project_LaneMgmt_DeleteLane_UploadButton}

Step ${step} User Clicks Download Template Link
    #************************Step 28******************************
    #  Do:
    #      User clicks download template link
    #  Expected:
    #      A document can be downloaded successfully
    #************************************************************
    ${filename1}    Download File    ${Project_LaneMgmt_DeleteLane_DownloadTemplate}
    Set Suite Variable    ${filename1}    ${filename1}

Step ${step} User Modify The Download Document To Add Lane ID 3
    #************************Step 29******************************
    #  Do:
    #      User modify the download document to add lane ID 3
    #      User clicks add file button and upload the file
    #  Expected:
    #      A tip that are you sure that these 1 lanes need to be
    #     deleted is appeared
    #************************************************************
    Modify Excel File    ${filename1}    2    1    REPORT    3
    Upload File By Selector    ${Project_LaneMgmt_DeleteLane_AddFile}    ${filename1}
    Wait Until Search Finished
    Wait Until Keyword Succeeds    10x    400ms    Get Page Source    contains    Are you sure that these 1 lanes need to be deleted? if so, please click confirm to continue.    100

Step ${step} User Clicks Confirm Button
    #************************Step 30******************************
    #  Do:
    #      User clicks confirm button
    #  Expected:
    #      Just wait a few seconds and a successful tip is
    #     appeared 1 lanes deleted successfully
    #************************************************************
    Click    ${Project_LaneMgmt_DeleteLane_ConfirmButton}
    Wait Until Search Finished
    Wait Until Keyword Succeeds    10x    400ms    Get Page Source    contains    lanes deleted successfully.    60

Step ${step} Select Update Existing Lanes Clicks Next Button
    #************************Step 31******************************
    #  Do:
    #      Select Update Existing Lanes clicks next button
    #  Expected:
    #      A new dialogue displays
    #************************************************************
    Click    ${Project_LaneMgmt_UpdateInfo}
    Click    ${Project_LaneMgmt_NextButton} 
    Wait Until Search Finished

Step ${step} User Clicks Download Button 2
    #************************Step 32******************************
    #  Do:
    #      User clicks download button
    #      Check the downloaded file
    #  Expected:
    #      There are only 3 lanes in it the lane3 is not in it
    #     only lane 1 2 4
    #************************************************************
    ${filename2}    Download File    ${Project_UpdateLane_DownloadButton} 
    Set Suite Variable    ${filename2}    ${filename2}
    Wait Until Search Finished
    Open Excel Document     ${filename2}    ${PROJECT.MODE}_D
    Check Cell Value    5    17    1    ${PROJECT.MODE}_D
    Check Cell Value    6    17    2    ${PROJECT.MODE}_D
    Check Cell Value    7    17    4    ${PROJECT.MODE}_D
    Close All Excel Documents

Step ${step} Click On Close Button
    #************************Step 33******************************
    #  Do:
    #      Click on Close button
    #      In Pricing Project page User selects TenderID Contains
    #     20240815
    #  Expected:
    #      The project with FCL mode could be found
    #************************************************************
    Wait For Elements State    ${Project_UpdateLane_CloseButton}    enabled    30
    Click    ${Project_UpdateLane_CloseButton}

Step ${step} Select This Project Click On Delete Project Button
    #************************Step 34******************************
    #  Do:
    #      Select this project click on Delete Project button
    #      Click Yes of the pop up confirm window
    #  Expected:
    #      System displays Project has been deleted
    #************************************************************
    Delete Project    ${G_TENDERID}

Step ${step} User goes to Basic Data Management Tender List 2
    #************************Step 35******************************
    #  Do:
    #      User goes to Basic Data Management Tender List
    #      Search out the tender created in step1
    #      Click on Delete button
    #      Click on Yes button in the popup dialog
    #  Expected:
    #      System displays Tender has been deleted
    #************************************************************
    Delete Tender    ${G_TENDERID}

